package com.redwine.app;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.umeng.analytics.MobclickAgent;

import static com.redwine.app.R.id.layout_back;

public class CommonWebViewActivity extends BaseActivity {

    @ViewInject(R.id.header_title)
    TextView header_title;
    @ViewInject(layout_back)
    LinearLayout layoutBack;
    @ViewInject(R.id.webview)
    WebView webview;

    public static final String TITLE_PARAMS = "TITLE_PARAMS";
    public static final String LOAD_URL = "LOAD_URL";
    private String mTitle;
    private String mUrl;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_common_webview);
        ViewUtils.inject(this);
        Intent intent = getIntent();
        if (null != intent) {
            mTitle = intent.getStringExtra(TITLE_PARAMS);
            mUrl = intent.getStringExtra(LOAD_URL);
        } else {
            finish();
        }
        header_title.setText(mTitle);
        layoutBack.setVisibility(View.VISIBLE);
        layoutBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
                overridePendingTransition(0, R.anim.base_slide_right_out);
            }
        });
        initweb();
    }

    private void initweb() {
        updateWebViewSettings(webview);
        webview.loadUrl(mUrl);
    }


    @Override
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("SplashScreen");
        MobclickAgent.onResume(this);
    }

    @Override
    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("SplashScreen");
        MobclickAgent.onPause(this);
    }

}
